<template>
	<div class="html_a">
		<van-nav-bar
		  title="修改价格"
		  left-arrow
		  @click-left="onClickLeft"
		>		
		  <van-icon name="arrow-left" slot="left" color="#000" size="20"/>
	   </van-nav-bar> 	 
	   
	   <div class="body">
	   	  <div class="section">
	   	  	<div class="info" @click="showPrice=true">
	   	  		<!--<div>订单单价 (元)</div>-->
	   	  		<!--<div >{{params.goodsPrice}}</div>-->
				<van-field
				  placeholder="请输入订单单价(元)"
				  input-align="right"
				  v-model="params.goodsPrice"
				  type="number"
				> 
				<div slot="label">
					<!--<span style="color: #F12613;">*</span>-->
					<span>订单单价 (元)</span>
				</div>			
				</van-field>	   	  		
	   	  	</div>
	   	  	<div class='tips'>总价(单件价格*数量):{{all}}元</div>
	   	  </div>
	   	  <div class="section">
	   	  	<div class="info" style="padding-bottom: 10px;" @click="showFrieht=true">
	   	  		<!--<div>运费 (元)</div>-->
	   	  		<!--<div >{{params.goodsFreight}}</div>-->
				<van-field
				  placeholder="请输入运费 (元)"
				  input-align="right"	
				  v-model="params.goodsFreight"
				  type="number"
				> 
				<div slot="label">
					<!--<span style="color: #F12613;">*</span>-->
					<span>运费 (元)</span>
				</div>			
				</van-field>	   	   	  		
	   	  	</div>
	   	  </div>	   	  
	   </div>
	   
	   <div class="confirm">
	   	   <van-button color="#FFD52F" block @click="confirm">
	   	     <span style="color: #333!important;font-size: 16px;">确认</span>	
	   	   </van-button>
	   </div>
	   
	   
	</div>		
</template>

<script>
import {getFun} from '@/api/publicFun.js'	 
let publicFun=getFun()	
export default {	
	data() {
       return {
          showPrice:false,
          showFrieht:false,
          params:{
          	ordersId:'',
          	goodsPrice:'0.00',
          	goodsFreight:'0.00',
          	goodsCount:0
          },
          url1:this.$api+'/marketorderservice/api/v1/market/orders/updateOrdersPrice', // 更新订单数据
          url2:this.$api+'/marketorderservice/api/v1/market/orders', // 获取订单数据
       }  
	},
	computed:{
		all:function(){
			if(this.params.goodsPrice){
				return (this.params.goodsPrice*this.params.goodsCount).toFixed(2)
			}else{
				return '0.00'
			}
			
		}	
	},
	methods: {
		 // 提交数据
		 confirm(){
		 	let that=this
		 	let reg=/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/		 	
		 	if(!reg.test(this.params.goodsPrice)){
		 		this.$toast('请输入正确的价格')
		 		return false
		 	}
	 	
		 	if(!reg.test(this.params.goodsFreight)){
		 		this.$toast('请输入正确的运费')
		 		return false
		 	}    	
		 	let ordersAllPay=(Number(this.all)+Number(this.params.goodsFreight)).toFixed(2)
	        if(ordersAllPay<0.5){
				this.$toast('总价不能低于0.50元')
				return false		        	
	        }
		 	this.$Axios2.Post(this.url1,this.params).then(function(res){
		 		that.onClickLeft()
		 	})
		 },
		 getData(){
		  let that=this	
		  // 获取分类
	      this.$Axios2.Get(this.url2+'/'+this.params.ordersId+'/'+this.userId).then(function(res) {	 
             that.params.goodsPrice=(res.data.orders.ordersPrice/res.data.orders.goodsCount).toFixed(2)
             that.params.goodsFreight=res.data.orders.goodsFreight.toFixed(2)
             that.params.goodsCount=res.data.orders.goodsCount
	      })	
		 }

	},
	mixins:[publicFun],//混入		
	mounted() {
		// 获取订单详情
		this.params.ordersId=this.$router.currentRoute.query.ordersId;
		this.getData()
	}
}	
</script>

<style scoped="" lang="scss">
.van-cell{padding: 0;}
.html_a{background: #f8f8f8;min-height: 100%;width: 100%;position: absolute;}
.body{padding: 10px;
  .section{background: #fff;padding: 15px 20px 0;
     .info{display: flex;align-items: center;justify-content: space-between;font-size: 14px;font-weight: 500;}
     .tips{text-align: right;color: #999;margin-top: 10px;border-bottom:1px solid #f0f0f0;padding-bottom: 10px;}
  }
}
.confirm{padding: 20px;}
</style>